package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;

import com.itheima.service.ReportService;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hql
 * @date 2019-12-13 10:38
 */
@RestController
@RequestMapping("/report")
public class ReportController {
   @Reference
    private SetmealService setmealService;
   @Reference
   private ReportService reportService;

    /**
     * 查询套餐的名字跟每个套餐所有的人数
     * @return
     */
    @RequestMapping("/getSetmealReport")
    public Result getSetmealReport(){

        try {
            //查询出套餐的名字跟每个套餐所有的人数
            List<Map<String,Object>> mapList =  setmealService.findSetmealCount();
            System.out.println(mapList);
            //将所有的名字封装到Map中去
            Map<String ,Object>  map= new HashMap<>();
            List<String> list = new ArrayList<>();
            for (Map<String, Object> objectMap : mapList) {
                String name = (String) objectMap.get("name");
                list.add(name);
            }
            map.put("setmealNames",list);
            //将查询出套餐的名字跟每个套餐所有的人数也封装到map中去
            map.put("setmealCount",mapList);
            //然后将所有的信息封装成集合返回给前台

            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }

    }

    /**
     * 返回所有前台所需要的数据
     * @return
     */
    @RequestMapping("/getBusinessReportData")
    public Result getBusinessReportData(){

        try {
            Map<String, Object> map = reportService.getBusinessReportData();
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS, map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }

    }
    }
